home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / FromTheMag / JW FLV MEDIA PLAYER 4.2 / mediaplayer.exe / player.swf / scripts / com / jeroenwijering / parsers / SMILParser.as < prev    next >
Text File  |  2008-11-04  |  4KB  |  136 lines

  1. package com.jeroenwijering.parsers
  2. {
  3.    import com.jeroenwijering.utils.Strings;
  4.    
  5.    public class SMILParser extends ObjectParser
  6.    {
  7.        
  8.       
  9.       public function SMILParser()
  10.       {
  11.          super();
  12.       }
  13.       
  14.       public static function parseAttributes(param1:Object, param2:Object) : Object
  15.       {
  16.          var _loc3_:Number = NaN;
  17.          var _loc4_:String = null;
  18.          _loc3_ = 0;
  19.          while(_loc3_ < param1.attributes().length())
  20.          {
  21.             _loc4_ = param1.attributes()[_loc3_].name().toString();
  22.             switch(_loc4_)
  23.             {
  24.                case "begin":
  25.                   param2["start"] = Strings.seconds(param1.@begin);
  26.                   break;
  27.                case "src":
  28.                   param2["file"] = param1.@src.toString();
  29.                   break;
  30.                case "dur":
  31.                   param2["duration"] = Strings.seconds(param1.@dur);
  32.                   break;
  33.                case "alt":
  34.                   param2["description"] = param1.@alt.toString();
  35.                   break;
  36.                default:
  37.                   param2[_loc4_] = param1.attributes()[_loc3_].toString();
  38.                   break;
  39.             }
  40.             _loc3_++;
  41.          }
  42.          return param2;
  43.       }
  44.       
  45.       public static function parse(param1:XML) : Array
  46.       {
  47.          var _loc2_:Array = null;
  48.          var _loc3_:Object = null;
  49.          var _loc4_:XML = null;
  50.          var _loc5_:XML = null;
  51.          _loc2_ = new Array();
  52.          _loc3_ = new Object();
  53.          if((_loc4_ = param1.children()[1].children()[0]).localName().toLowerCase() == "seq")
  54.          {
  55.             for each(_loc5_ in _loc4_.children())
  56.             {
  57.                _loc3_ = SMILParser.parseSeq(_loc5_);
  58.                if(_loc3_["type"] != undefined)
  59.                {
  60.                   _loc2_.push(_loc3_);
  61.                }
  62.                _loc3_ = {};
  63.             }
  64.          }
  65.          else
  66.          {
  67.             _loc2_.push(SMILParser.parsePar(_loc4_));
  68.          }
  69.          return _loc2_;
  70.       }
  71.       
  72.       public static function parseSeq(param1:Object) : Object
  73.       {
  74.          var _loc2_:Object = null;
  75.          _loc2_ = new Object();
  76.          switch(param1.localName().toLowerCase())
  77.          {
  78.             case "par":
  79.                _loc2_ = SMILParser.parsePar(param1);
  80.                break;
  81.             case "img":
  82.             case "video":
  83.             case "audio":
  84.                _loc2_ = SMILParser.parseAttributes(param1,_loc2_);
  85.          }
  86.          return ObjectParser.complete(_loc2_);
  87.       }
  88.       
  89.       public static function parsePar(param1:Object) : Object
  90.       {
  91.          var _loc2_:Object = null;
  92.          var _loc3_:XML = null;
  93.          _loc2_ = new Object();
  94.          for each(_loc3_ in param1.children())
  95.          {
  96.             switch(_loc3_.localName())
  97.             {
  98.                case "anchor":
  99.                   _loc2_["link"] = _loc3_.@href.toString();
  100.                   break;
  101.                case "textstream":
  102.                   _loc2_["captions"] = _loc3_.@src.toString();
  103.                   break;
  104.                case "img":
  105.                case "video":
  106.                case "audio":
  107.                   _loc2_[_loc3_.localName()] = _loc3_.@src.toString();
  108.                   _loc2_ = SMILParser.parseAttributes(_loc3_,_loc2_);
  109.                   break;
  110.             }
  111.          }
  112.          if(_loc2_["video"])
  113.          {
  114.             _loc2_["file"] = _loc2_["video"];
  115.             delete _loc2_["video"];
  116.          }
  117.          else if(_loc2_["audio"])
  118.          {
  119.             _loc2_["file"] = _loc2_["audio"];
  120.             delete _loc2_["audio"];
  121.          }
  122.          else if(_loc2_["img"])
  123.          {
  124.             _loc2_["file"] = _loc2_["img"];
  125.             delete _loc2_["audio"];
  126.          }
  127.          if(_loc2_["img"])
  128.          {
  129.             _loc2_["image"] = _loc2_["img"];
  130.             delete _loc2_["img"];
  131.          }
  132.          return _loc2_;
  133.       }
  134.    }
  135. }
  136.